﻿using DosTexPrj.Core.Models;
using FluentNHibernate.Mapping;

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    public class DyeOrderMapping : ClassMap<DyeOrder>
    {
        public DyeOrderMapping()
        {
            Table("DyeOrders");
            Id(x => x.Id, "DyeOrderID").UnsavedValue(0).GeneratedBy.Identity();
            References<Order>(x => x.BelongToOrder).Column("OrderID").Not.LazyLoad();
            References<OrderStatus>(x => x.OrderStatus).Column("OrderStatusID").Not.LazyLoad();
            References<Supplier>(x => x.BelongToSupplier).Column("SupplierID").Not.LazyLoad();
            References<Composition>(x => x.Composition).Column("CompositionID").Not.LazyLoad();
            Map(x => x.Article).Not.Nullable().Length(200);
            Map(x => x.Color).Not.Nullable().Length(100);
            Map(x => x.DeliveryAddress).Not.Nullable().Length(200);
            Map(x => x.DeliveryDate).Not.Nullable();
            Map(x => x.DyeInstruction).Not.Nullable().Length(500);
            Map(x => x.GMS).Not.Nullable();
            Map(x => x.Mt).Not.Nullable();
            Map(x => x.OrderDate).Not.Nullable();
            Map(x => x.Width).Not.Nullable();
            HasMany<DyeOrderDetail>(x => x.Details).KeyColumn("DyeOrderID").Not.LazyLoad()
                                                        .Cascade.AllDeleteOrphan()
                                                        .AsBag();
        }
    }
}